package com.ch.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author chenhong
 * @version 1.0.0
 * @ClassName MyController.java
 * @Description TODO
 * @createTime 2020年12月16日 17:25:00
 */

/**
 * 类上面的@RequestMapping的value是所有请求地址的公共部分，叫做模块名称
 * 位置：类上面
 */
@Controller
@RequestMapping("/test")
public class MyController {


    @RequestMapping(value = "/some.do" , method = RequestMethod.GET)
    public ModelAndView doSome(HttpServletRequest request){

        ModelAndView mav = new ModelAndView();
        //框架在最后会执行request.setAttribute
        mav.addObject("methodName","some");
        mav.addObject("msg","hello world");
        mav.addObject("kk","qs");
        //指定视图
        //框架对视图执行的操作是forward操作 request.getRequestDispather("/show.jsp").forward
        //执行转发
        // mav.setViewName("/show.jsp");
        //如果配置了视图解析器
        mav.setViewName("show");
        return mav;
    }

    @RequestMapping(value = "/other.do",method = RequestMethod.POST)
    public ModelAndView Other(){

        ModelAndView mav = new ModelAndView();
        //框架在最后会执行request.setAttribute
        mav.addObject("methodName","other");
        mav.addObject("msg","hello world");
        mav.addObject("kk","qs");
        //指定视图
        //框架对视图执行的操作是forward操作 request.getRequestDispather("/show.jsp").forward
        //执行转发
        // mav.setViewName("/show.jsp");
        //如果配置了视图解析器
        mav.setViewName("show");
        return mav;

    }
}
